//
//  BaseNavigationController.m
//  Weibo
//
//  Created by taoshanchang on 15/1/21.
//  Copyright (c) 2015年 taoshanchang. All rights reserved.
//

#import "BaseNavigationController.h"
#import "ThemeManager.h"

@interface BaseNavigationController ()

@end

@implementation BaseNavigationController

-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if(self){
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeNotification:) name:kThemeDidChangeNotification object:nil];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadThemeImage];

    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipAction:)];
    
    swipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swipeGesture];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kThemeDidChangeNotification object:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma  - mark notification
-(void)themeNotification:(NSNotification *)notification{
    [self loadThemeImage];

}

-(void)loadThemeImage{
    float version = [[[UIDevice currentDevice] systemVersion] floatValue];
    //版本是否符合新版，navigation在5.0一下要用不同的方式设置背景,下面注释的是另一种方法
    if(version>=5.0){
        UIImage *image = [[ThemeManager sharedInstance] getThemeImage:@"navigationbar_background"];
        [self.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    }else{
        [self.navigationBar setNeedsDisplay];
    }
    //是否响应这个方法
    //    if([self.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
    //        [self.navigationBar setBackgroundImage:<#(UIImage *)#> forBarMetrics:<#(UIBarMetrics)#>];
    //
    //    }
}
#pragma mark - action

-(void)swipAction:(UISwipeGestureRecognizer *)gesture{
    if(self.viewControllers.count > 1){
        if(gesture.direction == UISwipeGestureRecognizerDirectionRight){
            [self popViewControllerAnimated:YES];
        }
        
    }
    

}



@end
